package com.ruoyi.task.service.impl;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.task.domain.SubBankServerConfig;
import com.ruoyi.task.mapper.SubBankServerConfigMapper;
import com.ruoyi.task.service.ISubBankServerConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class SubBankServerConfigServiceImpl implements ISubBankServerConfigService {

    @Autowired
    SubBankServerConfigMapper subBankServerConfigMapper;

    @Autowired
    SysDeptMapper sysDeptMapper;

    @Override
    public List<SubBankServerConfig> selectServerConfigList(SubBankServerConfig subBankServerConfig) {
        return subBankServerConfigMapper.selectServerConfigList(subBankServerConfig);
    }

    @Override
    public int insertConfig(SubBankServerConfig config) {
        SysDept sysDept = sysDeptMapper.selectDeptById(config.getDeptId());
        config.setSubBankCode(sysDept.getDeptCode());
        config.setSubBankName(sysDept.getDeptName());
        return subBankServerConfigMapper.insertConfig(config);
    }

    @Override
    public void deleteConfigByIds(Long[] configIds) {
        subBankServerConfigMapper.deleteConfigByIds(configIds);
    }

    @Override
    public SubBankServerConfig selectServerConfigByServerId(Long ServerId) {
        return subBankServerConfigMapper.selectServerConfigByServerId(ServerId);
    }

    @Override
    public int updateSubSeverConfig(SubBankServerConfig config) {
        SysDept sysDept = sysDeptMapper.selectDeptById(config.getDeptId());
        config.setSubBankCode(sysDept.getDeptCode());
        config.setSubBankName(sysDept.getDeptName());

        config.setUpdateTime(DateUtils.getNowDate());
        System.out.println("SubBankServerConfig:" + config);
        return subBankServerConfigMapper.updateSubSeverConfig(config);
    }
}
